package demoMod.nanaki.actions;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.watcher.ChangeStanceAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.powers.AbstractPower;
import com.megacrit.cardcrawl.powers.watcher.CannotChangeStancePower;
import demoMod.nanaki.interfaces.StruckUpHook;
import demoMod.nanaki.stances.AbstractStrophe;
import demoMod.nanaki.stances.Strophe1;

import java.util.stream.Collectors;

public class StruckUpAction extends AbstractGameAction {
    @Override
    public void update() {
        AbstractPlayer p = AbstractDungeon.player;
        if (p.stance instanceof AbstractStrophe) {
            AbstractStrophe strophe = (AbstractStrophe) p.stance;
            AbstractStrophe nextStrophe = strophe.getNextStrophe();
            if (nextStrophe != null) {
                addToTop(new ChangeStanceAction(nextStrophe));
            } else {
                addToTop(new ChangeStanceAction("Neutral"));
            }
        } else {
            addToTop(new ChangeStanceAction(Strophe1.STANCE_ID));
        }

        if (p.hasPower(CannotChangeStancePower.POWER_ID)) {
            p.getPower(CannotChangeStancePower.POWER_ID).flash();
            this.isDone = true;
            return;
        }

        for (AbstractCard card : p.drawPile.group.stream().filter(c -> c instanceof StruckUpHook).collect(Collectors.toList())) {
            ((StruckUpHook) card).preStruckUp();
        }
        for (AbstractCard card : p.hand.group.stream().filter(c -> c instanceof StruckUpHook).collect(Collectors.toList())) {
            ((StruckUpHook) card).preStruckUp();
        }
        for (AbstractCard card : p.discardPile.group.stream().filter(c -> c instanceof StruckUpHook).collect(Collectors.toList())) {
            ((StruckUpHook) card).preStruckUp();
        }
        for (AbstractCard card : p.exhaustPile.group.stream().filter(c -> c instanceof StruckUpHook).collect(Collectors.toList())) {
            ((StruckUpHook) card).preStruckUp();
        }
        for (AbstractCard card : p.limbo.group.stream().filter(c -> c instanceof StruckUpHook).collect(Collectors.toList())) {
            ((StruckUpHook) card).preStruckUp();
        }
        for (AbstractPower power : p.powers.stream().filter(c -> c instanceof StruckUpHook).collect(Collectors.toList())) {
            ((StruckUpHook) power).preStruckUp();
        }
        this.isDone = true;
    }
}
